package com.tyj.movie.config;

import io.netty.util.concurrent.DefaultThreadFactory;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 日期: 2021/7/7 9:15
 * 作者: 谭友杰
 * 类说明:
 */
@ConfigurationProperties(prefix = "thread")
@Component
@Data
public class ThreadPoolConfig {
    /**
     * 线程池核心大小
     */
    private Integer coreSize;

    /**
     * 线程池最大大小
     */
    private Integer maxSize;

    /**
     * 线程保持活跃状态 当核心当大于核心大小时若线程没事做超过该值 会清除线程
     */
    private Integer keepAliveTime;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(coreSize,
                maxSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>());
    }
}
